package com.lemon.smartsafety.ui.adapter.notice;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.entity.notice.NoticeInfoVo;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.utils.common.StringUtils;

import java.util.List;

import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Cooliean on 16/3/29.
 */
public class NoticeAdapter extends LemonRcvAdapter<NoticeInfoVo> {
    private RecyclerTClickListener<NoticeInfoVo> mListener;

    public NoticeAdapter(@Nullable List<NoticeInfoVo> data) {
        super(data);
    }

    public NoticeAdapter(List<NoticeInfoVo> data, RecyclerTClickListener<NoticeInfoVo> listener) {
        super(data);
        this.mListener = listener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new NoticeItem();
    }

    public class NoticeItem implements AdapterItem<NoticeInfoVo> {

        LinearLayout ripple;
        TextView   tvItemTitle;
        TextView   tvStatus;
        TextView   tvUnit;
        TextView   tvDate;


        private NoticeInfoVo mData;
        private int          mPosition;


        @Override
        public int getLayoutResId() {
            return R.layout.item_notice_list;
        }

        @Override
        public void bindViews(View root) {
            ripple = (LinearLayout) root.findViewById(R.id.ripple);
            tvItemTitle = (TextView) root.findViewById(R.id.tv_item_title);
            tvStatus = (TextView) root.findViewById(R.id.tv_status);
            tvUnit = (TextView) root.findViewById(R.id.tv_unit);
            tvDate = (TextView) root.findViewById(R.id.tv_date);
        }

        @Override
        public void setViews() {
            ripple.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mListener != null) {
                        mListener.onItemClick(mData, mPosition);
                    }
                }
            });
       /*     ripple.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
                @Override
                public void onComplete(RippleView rippleView) {
                    if (mListener != null) {
                        mListener.onItemClick(mData, mPosition);
                    }
                }
            });*/
        }

        @Override
        public void handleData(NoticeInfoVo data, int position) {
            mData = data;
            mPosition = position;
            tvItemTitle.setText(StringUtils.nullValue(data.getTitle()));
            if (StringUtils.getBoolean(data.getHasRead())) {
                tvStatus.setText(StringUtils.getStatusString("已读", StringUtils.ColorStatus.STATUS_GREEN));
            } else {
                tvStatus.setText(StringUtils.getStatusString("未读", StringUtils.ColorStatus.STATUS_RED));
            }
            tvUnit.setText(StringUtils.nullValue(data.getGovName()));
            tvDate.setText(StringUtils.friendly_time(data.getRecordDate()));

        }
    }
}
